//
//  M4PublicAlertView.swift
//  M4
//
//  Created by YuChuang on 2024/8/9.
//

import UIKit

class M4PublicAlertView: UIView {
    
    @IBOutlet weak var M4AlertTitle: UILabel!
    
    @IBOutlet weak var M4FirstButton: UIButton!
    
    @IBOutlet weak var M4SecondButton: UIButton!
    
    @IBOutlet weak var M4SecondButtonTop: NSLayoutConstraint!
    
    @IBOutlet weak var M4SecondButtonHeight: NSLayoutConstraint!
    
    var M4AlertFirstBlock: (() -> Void)?
    
    var M4AlertSecondBlock: (() -> Void)?
    
    override func awakeFromNib() {
        self.frame = CGRect(x: 0, y: 0, width: M4ScreenWidth, height: M4ScreenHeight)
    }
    
    func m4updateAlertUI(title: String, firstText: String, secondText: String) {
        M4AlertTitle.text = title
        M4FirstButton.setTitle(firstText, for: .normal)
        M4SecondButton.setTitle(secondText, for: .normal)
        M4SecondButton.isHidden = secondText == "" ? true : false
        M4SecondButtonTop.constant = secondText == "" ? 0 : 20
        M4SecondButtonHeight.constant = secondText == "" ? 0 : 27
    }
    
    @IBAction func M4FirstButtonClick(_ sender: UIButton) {
        self.M4AlertViewHidden()
        M4AlertFirstBlock?()
        sender.M4EventUnavailable = false
    }
    
    @IBAction func M4SecondButtonClick(_ sender: UIButton) {
        self.M4AlertViewHidden()
        M4AlertSecondBlock?()
        sender.M4EventUnavailable = false
    }
    
}
